#!/bin/bash
local_dir="source/packages"
real_dir="D:\eclipse_cpp\workspace\android.hardware.automotive.evs1.0-sample\packages"
tmp=`ls ../ |grep tom |grep -v gz`
tomcat_dir=`cd ../$tmp;pwd`

clear
echo found tomcat:$tomcat_dir

function start_tomcat()
{
    echo start tomcat...
    cd  $1
    ./startup.sh
    cd -
}

function stop_tomcat()
{
    echo stop tomcat...
    cd  $1
    ./shutdown.sh
    cd -
}

function index()
{
    echo index...
    java -Xmx2048m -jar ./lib/opengrok.jar -W "./data/configuration.xml" -P -S -v -s "./source" -d "./data"
}

function link()
{
    echo make link...
    ln -s $local_dir  $real_dir
}

input=””
while [ “$input” != “q” ]
do
    echo [1]start tomcat
    echo [2]stop tomcat
    echo [3]index source
    echo [4]make dir link
    echo [q]quit this program
    read input
    if [ "$input" == "1" ] ; then
        start_tomcat $tomcat_dir/bin
     fi
    if [ "$input" == "2" ] ; then
        stop_tomcat $tomcat_dir/bin
    fi
    if [ "$input" == "3" ] ; then
        index
    fi
    if [ "$input" == "4" ] ; then
        link
    fi
    if [ "$input" == "q" ] ; then
        echo Bye now...;
    fi
done

